from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse
from django.shortcuts import render
from api.models import players,CreditRecord

# Create your views here.

# public function
# show player's credit
def query_player_credit(str_name):
    tl = list(CreditRecord.objects.filter(player__player_name=str_name).values('creditchange'))
    s = 0
    for i in tl:
        s+=i['creditchange']
    return s

# public api
# show player list
def list_player(request):
    lst = list(players.objects.values())
    for i in lst:
        i['credit'] = query_player_credit(i['player_name'])
    return JsonResponse({'ret':0,'data':[lst]})


def player_credit(request):
    return 